package com.dnr.arch.kernel.services.persistence.relations;

import java.util.ArrayList;
import java.util.Collection;

import com.dnr.arch.kernel.api.model.Value;
import com.dnr.arch.kernel.api.model.relations.Aggregation;
import com.dnr.arch.kernel.api.model.relations.Cardinality;
import com.dnr.arch.kernel.api.model.relations.Relation;
import com.dnr.arch.kernel.api.model.MetaClassInterface;

public class AggregationJPAImpl implements Aggregation{

	private Collection<MetaClassInterface> members = null;
	private Cardinality cardinalities[] = new Cardinality[2];
	
	public AggregationJPAImpl(MetaClassInterface c1, MetaClassInterface c2){
		members = new ArrayList<MetaClassInterface>();
		members.add(c1);
		members.add(c2);
	}
	
	public void setCardinalities(Cardinality card1, Cardinality card2){
		cardinalities[0] = card1;
		cardinalities[1] = card2;
	}
	
	public AggregationJPAImpl(MetaClassInterface c1, MetaClassInterface c2, Cardinality card1, Cardinality card2){
		members = new ArrayList<MetaClassInterface>();
		members.add(c1);
		members.add(c2);
		cardinalities[0] = card1;
		cardinalities[1] = card2;
		
	}
	
	@Override
	public Cardinality getCardinality(MetaClassInterface c) {
		// TODO Auto-generated method stub
		if(cardinalities[0]!=null & cardinalities[0].getMetaClass().getClassName().equals(c.getClassName())){
			return cardinalities[0];
		}
		if(cardinalities[1]!=null & cardinalities[1].getMetaClass().getClassName().equals(c.getClassName())){
			return cardinalities[1];
		}
		return null;
	}

	@Override
	public Collection<MetaClassInterface> getMembers() {
		return members;
	}

	@Override
	public MetaClassInterface getOwner() {
		return ((ArrayList<MetaClassInterface>)members).get(0);
	}

}
